/**
 * $Date: $
 * $Rev: 000 $
 * $Author: $
 */

#import "NSString+Additions.h"
#import <Foundation/Foundation.h>


#import <SenTestingKit/SenTestingKit.h>

@interface NSStringTest : SenTestCase
{
}
@end

@implementation NSStringTest

- (void)setUp
{
}

- (void)tearDown
{
}

- (void)testEmpty
{
	STAssertTrue( [NSString IsEmpty:nil], @"Nil string" );
	STAssertTrue( [NSString IsEmpty:@""], @"Empty string" );
	
	STAssertFalse( [NSString IsEmpty:@" "], @"one space" );
	STAssertFalse( [NSString IsEmpty:@"david aspinall"], @"my name space" );
}

- (void)testTrim
{
	STAssertEqualObjects( [@"" trimWhiteSpace], @"", @"empty string" );
	STAssertEqualObjects( [@" " trimWhiteSpace], @"", @"one space" );
	
	STAssertEqualObjects( [@"  a " trimWhiteSpace], @"a", @"one char surrounded by spaces" );
	STAssertEqualObjects( [@"  a b " trimWhiteSpace], @"a b", @"one space between chars" );
}

- (void)testElipsis
{
	// no elipsis
	STAssertEqualObjects( [@"" stringByAppendingElipsisAfterCharacters:1], @"", @"empty string" );
	STAssertEqualObjects( [@" " stringByAppendingElipsisAfterCharacters:1], @" ", @"one space" );
	STAssertEqualObjects( [@"12345" stringByAppendingElipsisAfterCharacters:9], @"12345", @"after 9 char for strig of 5" );
	
	// adds elipsis
	STAssertEqualObjects( [@"   " stringByAppendingElipsisAfterCharacters:1], @" ...", @"one space" );
	STAssertEqualObjects( [@"12345" stringByAppendingElipsisAfterCharacters:3], @"123...", @"after 3 char" );
	STAssertEqualObjects( [@"1234567890" stringByAppendingElipsisAfterCharacters:9], @"123456789...", @"after 9 char" );
}


- (void)testUUID
{
	NSString *test = [NSString stringWithUUID];
	NSString *test2 = [NSString stringWithUUID];
	
	STAssertNotNil( test, @"no uuid" );
	STAssertNotNil( test2, @"no uuid" );
	STAssertFalse( [test isEqual:test2], @"UUID's are equal" );
}


- (void)testMD5
{
	NSString *test = [@"plan-b software" md5Hash];
	NSString *md5 = @"9d7c9ca3c34f1473f3cc3d7ff85d9172XXX";
	STAssertTrue( [md5 isEqual:test], @"Hash does not match %@ != %@", md5, test );
}


@end
